package com.cn.pack.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;
import java.util.Set;

@RestController
@Api(description = "测试源服务API接口")
public class ClientAController {

    @ApiOperation(value = "client.save", notes = "client.save")
    @GetMapping(path = "/save")
    public String save(@RequestParam("id") String id) {
        System.out.println("****************** save *****************" + id);
        return "****************** save *****************" + id;
    }

    @ApiOperation(value = "/get", notes = "/get")
    @RequestMapping(path = "/get")
    public String get(@RequestParam(value = "name") String name, @RequestParam("age") String age,
                      @RequestParam("cardNum") String cardNum, HttpServletRequest request) {
        System.out.println("-------------------");
        System.out.println("name = " + name);
        System.out.println("age = " + age);
        System.out.println("cardNum = " + cardNum);

        String appId = request.getHeader("appId");
        System.out.println("appId = " + appId);

        return "************ success";
    }

    @ApiOperation(value = "/query", notes = "/query")
    @RequestMapping(path = "/query")
    public void query(HttpServletRequest request) {
        Map<String, String[]> parameterMap = request.getParameterMap();
        Set<Map.Entry<String, String[]>> set = parameterMap.entrySet();
        System.out.println("*******************");
        for (Map.Entry<String, String[]> entry : set) {
            System.out.println(entry.getKey() + " = " + entry.getValue()[0]);
        }
    }
}
